﻿using Microsoft.Extensions.DependencyInjection;

using System;
using System.Linq;

using zijian666.DI.Abstractions;
using zijian666.DI.Features;

namespace zijian666.DI
{
    /// <summary>
    /// 配置服务切面, 用于自动启用装配服务
    /// </summary>
    /// <remarks>
    /// AddStartup 之后才能生效
    /// </remarks>
    internal class AutowiredAspect : IConfigureServicesFilter
    {
        public void EndConfigureServices(IServiceCollection services, Type configureType, object[] param)
        {
            if (services.Any(x => x.ServiceType == typeof(IAutowiredContext)))
            {
                services.AddAutowired();
            }
        }
    }
}
